package com.lizy

import org.junit.Test

class MethodTest {


    /**
     * 习题1
     */
    @Test
    public void test1() {
        def s = square(2)
        println(s);
    }
    def square(edge) {
        return edge ** 2;
    }

    /**
     * 习题3 正在生产
     */
    @Test
    public void test2() {
        def b = compare(11,14,"PM",1,23,"AM");
        println(b);
    }

    def compare(fHour,fMinute,fInterval,sHour,sMinute,sInterval) {
        def fMinutes = twelveToTwentyFour(fHour,fInterval) * 60 + fMinute;
        def sMinutes = twelveToTwentyFour(sHour, sInterval)*60 + sMinute;
        return fMinutes>=sMinutes;
    }
    def twelveToTwentyFour(hour, interval) {
        if(hour >12 || hour < 0) {
            throw new RuntimeException("不是十二小时制的时间");
        }
        if(interval == "PM") {
            return hour + 12;
        }
        return hour;
    }
}
